<%- include('../../ejs/auth/login.ejs') %>
<script type="text/javascript">
    $(function(){
        JSBridge.prototype.registerHandler("initLoginInfo", initLoginInfo);
        page_login.init({
            loginHandler: function(){
                var options = getOption();
                /**获取是否记住密码和是否自动登录**/
                $(".check-box").each(function () {
                    var id = $(this).attr("id");
                    if ($(this).is(":checked")) {
                        options[id] = "true";
                    } else {
                        options[id] = "false";
                    }
                });
                $.JkcsUserInfo.getUserInfoGzd({
                    callback: function(userInfo){
                        if(JSON.stringify(userInfo)){
                            $.QuickRemote.AjaxJson({
                                funcName: "/api/gzd/getUserHxid"
                                ,callback: function(hxInfo){
                                    if(hxInfo && hxInfo.username){
                                        options.easemob= hxInfo;
                                    }else{
                                        options.easemob= {
                                            username:"",
                                            password:""
                                        };
                                    }
                                    options.easemob.nickname = userInfo.xm;
                                    options.easemob.photo="";
                                    $.JkcsUtils.gotoHome(options);
                                }
                            });
                        }else{
                            $.QuickAlert.alertFail({
                                content: "获取用户信息失败"
                            });
                        }
                    }
                    ,refresh: true
                });
            }
        });
    })

    //组装option 传给原生
    function getOption(){
        var index_url=  $.getUrl.pageUrl("index","index")
        if(StoreCache.getCache("afterLoginUrl") && StoreCache.getCache("afterLoginUrl").indexOf("login")<0){
            index_url =  StoreCache.getCache("afterLoginUrl");
        }
        var options = {url: index_url, title: "主页", app_user_agent: 'mobile_app_jkcs', isLogin: true};
        /**获取用户名密码**/
        var username = $("#username").val();
        var password = $("#password").val();
        options["username"] = username;
        options["password"] = password;
        options.cover_url="http://139.224.33.116:1666";
        options.dysj="180";
        return options;
    }

    /**加载登录信息*/
    function initLoginInfo(info) {
        $("#username").val(info["username"]);
        var isSavaPass = info["isSavaPass"];
        if (isSavaPass == "true") {
            $("#isSavaPass").prop("checked", true);
            $("#password").val(info["password"]);
            if (info["isAutoLogin"] == "true") {
                $("#isAutoLogin").prop("checked", true);
                $("#btnLogin").trigger("click");
            }
        }
    }
</script>